<extend name="Public:base" />

<block name="content-wrapper">
	<!-- Content Wrapper. Contains page content -->
	<div class="content-wrapper">
		<!-- Content Header (Page header) -->
		<section class="content-header">
			<h1>
				添加学生
				<small>Add Student</small>
			</h1>
			<ol class="breadcrumb">
				<li>
					<a href="{:U('Index/index')}"> <i class="fa fa-dashboard"></i>
						首页
					</a>
				</li>
				<li>
					<a href="{:U('Student/index')}">学生管理</a>
				</li>
				<li class="active">添加学生</li>
			</ol>
		</section>

		<!-- Main content -->
		<section class="content">
			<div class="row">
				<div class="col-sm-6 col-sm-offset-3">
					<div class="box">
						<div class="box-header with-border">
							<h3 class="box-title">表单</h3>
						</div>
						<!-- /.box-header -->
						<!-- form start -->
						<div class="box-body">
							<form id="form-add" class="form-horizontal" action="{:U('Student/addPost')}" method="post">
								<div class="form-group">
									<label class="col-sm-2 control-label">学号</label>
									<div class="col-sm-9">
										<input name="id" id="id" type="number" class="form-control">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">密码</label>
									<div class="col-sm-9">
										<input name="password" id="password" type="password" class="form-control">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">确认密码</label>
									<div class="col-sm-9">
										<input name="repassword" id="repassword" type="password" class="form-control">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">姓名</label>
									<div class="col-sm-9">
										<input name="name" id="name" type="text" class="form-control">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">学院</label>
									<div class="col-sm-9">
										<select id="academy_id" class="form-control">
											<volist name="academies" id="vo">
												<eq name="vo.id" value="$academy_id">
													<option value="{$vo.id}" selected="selected">{$vo.name}</option>
												<else />
													<option value="{$vo.id}">{$vo.name}</option>
												</eq>																								
											</volist>
						                 </select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">专业</label>
									<div class="col-sm-9">
										<select name="major_id" id="major_id" class="form-control">
											<volist name="majors" id="vo">
												<option value="{$vo.id}">{$vo.name}</option>												
											</volist>
						                 </select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">年级</label>
									<div class="col-sm-9">
										<select name="grade" id="grade" class="form-control">
											<volist name="grades" id="vo">
												<eq name="vo.grade" value="$grade">
													<option value="{$vo.grade}" selected="selected">{$vo.grade}级</option>
												<else />
													<option value="{$vo.grade}">{$vo.grade}级</option>
												</eq>																								
											</volist>
						                 </select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">班号</label>
									<div class="col-sm-9">
										<select name="class" id="class" class="form-control">
											<volist name="class_numbers" id="vo">
												<eq name="vo.class" value="$class_number">
													<option value="{$vo.class}" selected="selected">{$vo.class}</option>	
												<else />
													<option value="{$vo.class}">{$vo.class}</option>
												</eq>											
											</volist>
						                 </select>
									</div>
								</div>								
							</form>
						</div>
						<!-- /.box-body -->
						<div class="box-footer">
							<a href="{:U('Student/index')}" type="button" class="btn btn-default">返回</a>
							<button id="button-add-submit" type="button" class="btn btn-info pull-right">确定</button>
						</div>
						<!-- /.box-footer -->
					</div>				
				</div>			
			</div>
		</section>
		<!-- /.content -->
	</div>
	<!-- /.content-wrapper -->
</block>

<block name="additional-scripts">
	<script>
		$(function () {
			$('#academy_id').change(function() {
				var academy_id = $('#academy_id').val();
				$.post('__MODULE__/Class/getMajorsByAcademyId',
				{
					academy_id: academy_id
				},
				function(data, status) {
					$('#major_id').empty();
					var majors = data;
					for(var key in majors) {
						$('#major_id').append('<option value="' + majors[key]['id'] + '">' + majors[key]['name'] + '</option>');
					}
					$('#major_id').change();
				});
			});

			$('#major_id').change(function() {
				var major_id = $('#major_id').val();
				$.post('__MODULE__/Student/getGradesByMajorId',
				{
					major_id: major_id
				},
				function(data, status) {
					$('#grade').empty();
					var grades = data;
					for(var key in grades) {
						$('#grade').append('<option value="' + grades[key]['grade'] + '">' + grades[key]['grade'] + '</option>');
					}
					$('#grade').change();
				});
			});

			$('#grade').change(function() {
				var major_id = $('#major_id').val();
				var grade = $('#grade').val();
				$.post('__MODULE__/Student/getClassNumbers',
				{
					major_id: major_id,
					grade: grade
				},
				function(data, status) {
					$('#form-add #class').empty();
					var class_numbers = data;
					for(var key in class_numbers) {
						$('#form-add #class').append('<option value="' + class_numbers[key]['class'] + '">' + class_numbers[key]['class'] + '</option>');
					}
				});
			});

			$('#button-add-submit').click(function() {
				$('#form-add').submit();
			});
		});
	</script>
</block>